﻿using System;
using NPoco;

namespace OrchardFork.Framework.Data
{
    public class BaseDao : IBaseDao, IDisposable
    {
        //设置线程副本，保证请求时数据连接的独立性
        [ThreadStatic]
        private static IDatabase _database;
        private static readonly object Lockobject = new object();

        public IDatabase GetDatabase()
        {
            lock (Lockobject)
            {
                if (_database != null)
                {
                    return _database;
                }
                return _database = new Database("ConnectionUrl");
            }
        }

        public void Dispose()
        {
            Console.WriteLine("(Dispose) - 释放了(线程: {0})", this.GetHashCode());
        }
    }
}
